home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
260_01
/
rz.c
< prev
next >
Wrap
Text File
|
1988-02-23
|
34KB
|
1,413 lines
#define VERSION "1.14 01-15-87"
#define PUBDIR "/usr/spool/uucppublic"
/*% cc -DNFGVMIN -DCRCTABLE -K -O -i % -o rz; size rz
*
* rz.c By Chuck Forsberg
* MS-DOS version by Francois Bergeon
*
* cc -O rz.c -o rz USG (3.0) Unix
* cc -O -DV7 rz.c -o rz Unix V7, BSD 2.8 - 4.3
* cl rz.c -link stty MS-DOS, MS-C 4.00+
*
* ln rz rb For USG or V7
*
* ln rz /usr/bin/rzrmail For remote mail. Make this the
* login shell. rzrmail then calls
* rmail(1) to deliver mail.
*
* define CRCTABLE to use table driven CRC
*
* Unix is a trademark of Western Electric Company
*
* A program for Unix to receive files and commands from computers running
* Professional-YAM, PowerCom, YAM, IMP, or programs supporting XMODEM.
* rz uses Unix buffered input to reduce wasted CPU time.
*
* Iff the program is invoked by rzCOMMAND, output is piped to
* "COMMAND filename"
*
* Some systems (Venix, Coherent, Regulus) may not support tty raw mode
* read(2) the same way as Unix. ONEREAD must be defined to force one
* character reads for these systems. Added 7-01-84 CAF
*
* Alarm signal handling changed to work with 4.2 BSD 7-15-84 CAF
*
* NFGVMIN Added 1-13-85 CAF for PC-AT Xenix systems where c_cc[VMIN]
* doesn't seem to work (even though it compiles without error!).
*
* HOWMANY should be tuned for best performance
*
* USG UNIX (3.0) ioctl conventions courtesy Jeff Martin
*
* MS-DOS Adaptation 10-19-87 for the MS-C compiler rev 4.00+
* using Francois Bergeon's tty library
*/
#define LOGFILE "/tmp/rzlog"
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
#include <ctype.h>
#ifdef MSDOS
#include <time.h>
#define CRCTABLE
#define JAN1ST70 315532800
#else
FILE *popen();
#endif
#define OK 0
#define FALSE 0
#define TRUE 1
#define ERROR (-1)
/*
* Max value for HOWMANY is 255.
* A larger value reduces system overhead but may evoke kernel bugs.
* 133 corresponds to a XMODEM/CRC sector
*/
#ifndef HOWMANY
#define HOWMANY 133
#endif
int Zmodem = 0; /* ZMODEM protocol requested */
int Nozmodem = 0; /* If invoked as "rb" */
unsigned Baudrate;
#include "rbsb.c" /* most of the system dependent stuff here */
char *substr();
FILE *fout;
/*
* Routine to calculate the free bytes on the current file system
* ~0 means many free bytes (unknown)
*/
long getfree()
{
return(~0L); /* many free bytes ... */
}
/* Ward Christensen / CP/M parameters - Don't change these! */
#define ENQ 005
#define CAN ('X'&037)
#define XOFF ('s'&037)
#define XON ('q'&037)
#define SOH 1
#define STX 2
#define EOT 4
#define ACK 6
#define NAK 025
#define CPMEOF 032
#define WANTCRC 'C' /* send C not NAK to get crc not checksum */
#define TIMEOUT (-2)
#define RCDO (-3)
#define ERRORMAX 5
#define RETRYMAX 5
#define WCEOT (-10)
#define SECSIZ 128 /* cp/m's Magic Number record size */
#define PATHLEN 257 /* ready for 4.2 bsd ? */
#define KSIZE 1024 /* record size with k option */
#define UNIXFILE 0x8000 /* happens to the the S_IFREG file mask bit for stat */
int Lastrx;
int Crcflg = FALSE;
int Firstsec;
int Eofseen; /* indicates cpm eof (^Z) has been received */
int errors;
int Restricted = 0; /* restricted; no /.. or ../ in filenames */
#ifdef ONEREAD /* Sorry, Regulus and some others don't */
int Readnum = 1; /* work right in raw mode! */
#else
int Readnum = HOWMANY; /* Number of bytes to ask for in read() from modem */
#endif
#define DEFBYTL 2000000000L /* default rx file size */
long Bytesleft; /* number of bytes of incoming file left */
long Modtime; /* Unix style mod time for incoming file */
short Filemode; /* Unix style mode for incoming file */
char Pathname[PATHLEN];
char *Progname; /* the name by which we were called */
int Batch = 0;
int Wcsmask = 0377;
int Topipe = 0;
int MakeLCPathname = TRUE; /* make received pathname lower case */
int Verbose = 0;
int Quiet = 0; /* overrides logic that would otherwise set verbose */
int Nflag = 0; /* Don't really transfer files */
int Rxbinary = FALSE; /* receive all files in bin mode */
int Rxascii = FALSE; /* receive files in ascii (translate) mode */
int Thisbinary; /* current file is to be received in bin mode */
int Blklen; /* record length of received packets */
char secbuf[KSIZE];
char linbuf[HOWMANY];
int Lleft = 0; /* number of characters in linbuf */
time_t timep[2];
char Lzmanag; /* Local file management request */
char zconv; /* ZMODEM file conversion request */
char zmanag; /* ZMODEM file management request */
char ztrans; /* ZMODEM file transport request */
jmp_buf tohere; /* For the interrupt on RX timeout */
#include "zm.c"
int tryzhdrtype = ZRINIT; /* Header type to send corresponding to */
/* Last rx close */
alrm()
{
longjmp(tohere, -1);
}
/* called by signal interrupt or terminate to clean things up */
bibi(n)
{
if (Zmodem)
zmputs(Attn);
canit();
mode(0);
fprintf(stderr, "rz: caught signal %d; exiting\n", n);
exit(128+n);
}
main(argc, argv)
char *argv[];
{
char *cp;
register npats;
char *virgin, **patts;
char *getenv();
int exitcode;
Rxtimeout = 100;
setbuf(stderr, NULL);
if ((cp = getenv("SHELL")) && (substr(cp, "rsh") || substr(cp, "rksh")))
Restricted = TRUE;
#ifndef MSDOS
chkinvok((virgin = argv[0])); /* if called as [-]rzCOMMAND set flag */
#else
Progname = virgin = "rz";
#endif
npats = 0;
while (--argc)
{
cp = *++argv;
if (*cp++ == '-' && *cp)
{
while (*cp)
{
switch (*cp++)
{
case '+':
Lzmanag = ZMAPND;
break;
#ifndef MSDOS
case '1':
iofd = 1;
break;
#else
case '2':
port = "COM2";
break;
case 's':
Baudrate = atoi(cp);
if ((speed = getspeed(Baudrate)) < 0)
usage();
*cp = '\0';
break;
case 'Y':
Nozmodem = TRUE;
break;
#endif
case '7':
Wcsmask = 0177;
case 'a':
Rxascii = TRUE;
break;
case 'b':
Rxbinary = TRUE;
break;
case 'c':
Crcflg = TRUE;
break;
case 'D':
Nflag = TRUE;
break;
case 'p':
Lzmanag = ZMPROT;
break;
case 'q':
Quiet = TRUE;
Verbose = 0;
break;
case 't':
if (--argc < 1)
usage();
Rxtimeout = atoi(*++argv);
if (Rxtimeout < 10 || Rxtimeout > 1000)
usage();
break;
case 'u':
MakeLCPathname = FALSE;
break;
case 'v':
++Verbose;
break;
default:
usage();
}
}
}
else if (!npats && argc > 0)
{
if (argv[0][0])
{
npats = argc;
patts = argv;
#ifde